<template>
  <div>
    <hs-breadcrumb :breadcrumb="breadcrumb"></hs-breadcrumb>
    <Card :bordered="false" :style="{ marginBottom: '10px' }">
      <div class="hs-screen-row">
        <DatePicker
          @on-change="changeDate"
          v-model="dateInit"
          type="daterange"
          :editable="false"
          separator=" ~ "
          split-panels
          transfer
          placeholder="选择日期"
          style="width: 200px"
        ></DatePicker>
      </div>
      <div class="hs-screen-row">
        <Button type="primary" @click="findOrderMallList">查询</Button>
      </div>
      <div class="hs-screen-row">
        <Button @click="resetScreen">重置</Button>
      </div>
    </Card>

    <Card :bordered="false" :style="{ marginBottom: '10px' }">
      <!--标题-->
      <div slot="title">
        <div class="hs-screen-box">
          <div>订单列表</div>
          <div>
            <ButtonGroup>
              <Button @click="findOrderMallList">
                <Icon type="md-refresh" size="15" />
              </Button>
            </ButtonGroup>
          </div>
        </div>
      </div>

      <!--表格数据-->
      <Table
        :columns="columns"
        :data="dataList"
        size="small"
        :stripe="true"
        :loading="isTableLoading"
      >
        <template slot-scope="{ row }" slot="action">
          <Button
            type="info"
            size="small"
            ghost
            style="margin-right: 5px"
            @click="goOrderList(row)"
          >
            查看
          </Button>
        </template>
      </Table>
      <!--分页-->
      <div class="hs-page">
        <Page
          :total="total"
          show-sizer
          show-total
          transfer
          @on-change="changePage"
          @on-page-size-change="changePageSize"
        />
      </div>
    </Card>
  </div>
</template>

<script>
  import hsBreadcrumb from '@/components/hs-breadcrumb';
  import orderOpe from './components/order-ope';
  import orderLogisticsTracking from './components/order-logistics-tracking';
  import orderLogisticsNumber from './components/order-logistics-number';
  import orderCustomRefund from './components/order-custom-refund';
  import moment from 'moment';
  export default {
    name: 'admin',
    data() {
      return {
        dateInit: '',
        showExp: false,
        total: 0,
        importSuccess: 0,
        importFailed: 0,
        isTableLoading: false,
        isShowImport: false,
        action: this.$apiURL + '/orderMall/importOrderExcel',
        headers: {
          token: JSON.parse(sessionStorage.getItem('J-TOKEN')).token
        },
        // 参数
        params: {
          page: 1,
          rows: 10,
          startTime: '',
          endTime: '',
          billId: ''
        },
        // 表格列
        columns: [
          {
            type: 'index',
            width: 60,
            align: 'center'
          },
          {
            title: '日期',
            minWidth: 120,
            key: 'billDate'
          },
          {
            title: '订单数量',
            minWidth: 190,
            key: 'orderNum'
          },
          {
            title: '物品数量',
            minWidth: 190,
            key: 'countNum',
            ellipsis: true
          },
          {
            title: '预计收益',
            minWidth: 120,
            key: 'income'
          },
          {
            title: '时间',
            minWidth: 120,
            key: 'createTime'
          },
          { title: '操作', minWidth: 100, slot: 'action' }
        ],
        failOrderData: [],
        // 面包屑
        breadcrumb: [
          { name: '首页', url: '', icon: 'ios-home-outline', size: 18 },
          { name: '洗衣管理', url: '', icon: '', size: 0 },
          { name: '工厂对账', url: '', icon: '', size: 0 }
        ],
        dataList: [],
        expType: 'send',
        orderCode: ''
      };
    },
    computed: {},
    created() {
      // 订单-列表查询
      this.findOrderMallList();
    },
    methods: {
      goOrderList(row) {
        this.$router.push({
          path: '/index/wash/order',
          query: {
            billId: row.id
          }
        });
      },

      // 日期条件赋值
      changeDate(e) {
        this.params.startTime = e[0];
        this.params.endTime = e[1];
      },
      // 订单-列表查询
      findOrderMallList() {
        this.isTableLoading = true;
        this.axios.post('/bill/billList', this.params).then(res => {
          console.log(res);
          this.isTableLoading = false;
          if (res.status == 200) {
            this.total = res.data.total;
            this.dataList = res.data.rows.map(item => ({
              ...item,
              createTime: moment(item.createTime).format('yyyy-MM-DD hh:mm:ss')
            }));
          }
          if (res.status == 500) {
            this.$Notice.error({
              title: '服务器内部错误',
              desc: '查询订单列表接口报错',
              duration: 0
            });
          }
        });
      },

      // 导出订单Excel
      exportExcel() {
        this.$Spin.show();
        this.axios
          .post('/orderMall/exportExcel', this.params, {
            responseType: 'arraybuffer'
          })
          .then(res => {
            setTimeout(() => {
              this.$Spin.hide();
            }, 300);
            //
            let blob = new Blob([res], { type: 'Files' });
            let csvUrl = URL.createObjectURL(blob);
            let link = document.createElement('a');
            link.href = csvUrl;
            // 下载xlsx文件
            link.download = '商品订单列表.xls';
            link.click();
            if (res.status == 201) {
              // this.$Message.error(res.msg);
              this.$Notice.error({
                title: '删除订单失败',
                desc: res.msg
              });
            }
            if (res.status == 500) {
              this.$Notice.error({
                title: '服务器内部错误',
                desc: '删除订单接口报错',
                duration: 0
              });
            }
          });
      },
      // 显示操作模态框
      showOrderOpe(row) {
        this.$refs.orderOpe.show(row);
      },
      // 重置筛选条件
      resetScreen() {
        this.params.startTime = '';
        this.params.endTime = '';
        this.dateInit = '';
      },
      // 改变页数
      changePage(e) {
        this.params.page = e;
        this.findOrderMallList();
      },
      // 改变页容量
      changePageSize(e) {
        this.params.rows = e;
        this.findOrderMallList();
      }
    },
    components: {
      hsBreadcrumb,
      orderOpe,
      orderLogisticsTracking,
      orderLogisticsNumber,
      orderCustomRefund
    }
  };
</script>

<style scoped lang="less">
  .circle {
    width: 14px;
    height: 14px;
    border-radius: 7px;
    &-1 {
      background-color: #19be6b;
    }
    &-2 {
      background-color: #f90;
    }
    &-3 {
      background-color: crimson;
    }
  }
  .hs-upload-image-box {
    width: 485px;
    display: flex;
    align-items: center;
    justify-content: center;

    .hs-upload-add {
      cursor: pointer;
      width: 100%;
      height: 43px;
      display: flex;
      align-items: center;
      justify-content: center;
      border: 1px dashed #cccccc;
      transition: all 0.3s;

      &:hover {
        color: #2d8cf0;
        border: 1px dashed #2d8cf0;
      }
    }
  }
  .z-import-message {
    margin: 10px 0;
  }
</style>
